﻿using Microsoft.SqlServer.Server;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace Lesson23_面向对象编程_string
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //字符串的本质是一个char数组 
            #region 字符串指定位置获取
            //string str = "唐老师";
            //foreach(char c in str)
            //{
            //    Console.Write(c + " ");
            //}
            //Console.WriteLine();
            //Console.WriteLine(str[0]);

            #endregion

            #region 字符串拼接  Foramt
            string str;
            str = string.Format("{0}{1}", 123, 456);
            Console.WriteLine(str);
            #endregion

            #region 正向查找字符位置  IndexOf()
            //str = "唐老师";
            //int index = str.IndexOf("唐");   //如果没找到，默认返回-1
            //Console.WriteLine(index);
            #endregion

            #region 反向查找字符位置  
            //从后面往前找第一个出现的位置

            str = "我是唐老师唐老师";
            int index = str.LastIndexOf("唐");
            Console.WriteLine(index);  //从前往后计算位置
                                       //没找到返回-1
                                       //输出结果为5
            #endregion

            #region  移除指定位置之后的字符 
            str = "我是唐老师";
            string s = str.Remove(2);
            string a = str.Remove(1,2); /* Remove(开始位置，删除个数)*/
            Console.WriteLine(s);
            Console.WriteLine(a);
            #endregion

            #region 替换指定字符串 
            str = "我是唐老师真牛逼";
            string s1 = str.Replace("唐老师", "张狗蛋");
            string s2 = str.Replace("我", "你");
            Console.WriteLine(s1);
            Console.WriteLine(s2);
            #endregion

            #region 大小写转换  str.ToUpper()  大转小  str.ToLower()  小转大
            str = "akdflafghausjd";
            string z = str.ToUpper();
            Console.WriteLine(z);
            string m = str.ToLower();
            Console.WriteLine(m);
            #endregion

            #region 字符串截取
            str = "今天你消耗了多少卡路里";
            string q = str.Substring(2,4);
            Console.WriteLine(q);
            #endregion

            #region 字符串切割 非常重要！！！
            str = "AI时代已经到来,你还在等什么";
            
            string[] n = new string[100]; 
            n = str.Split(',');   
            foreach (string y in n)
            {
                Console.WriteLine( y);
            }

            string s9 = "1,2,3,4,5,6,7,8,9";
            string[] s10 = s9.Split(',');
            foreach(String i in s10)
            {
                Console.Write(i);
            }
            Console.WriteLine("         ");
            string P = "1-1|2-2|3-3|4-4|5-5|6-6|7-7|";

            string[] r = P.Split('|');
            foreach (string g in r)   
                Console.WriteLine(g);
            string[] e = P.Split('-');
            foreach(string ing  in e)
            {
                Console.WriteLine(ing);
            }    
            #endregion
        }
    }
}
